package com.tcpengine.net;
import com.alibaba.fastjson.JSON;
import com.tcpengine.client.LogView;
import com.tcpengine.dao.UserInfo;

import io.netty.channel.Channel;


// 业务逻辑处理过程
public class GameProcess {
	
	public static void handle(Channel ch, Msg msg, int netType, LogView logView) {	// 处理消息
		if(1000 == msg.id) {	// 登陆处理
			byte[] byMsg = new byte[msg.bodyLen];
			msg.body.readBytes(byMsg);
			logView.println("收到服务端响应的登陆消息：" + new String(byMsg));
		}
		else if(1001 == msg.id) {
			
			int iStrNameLen = msg.body.readInt();	// 字符串名字长度
			byte[] byName = new byte[iStrNameLen];
			msg.body.readBytes(byName);
			String strName = new String(byName);
			int userId = msg.body.readInt();
			float money = msg.body.readFloat();
			long gold = msg.body.readLong();
			byte sex = msg.body.readByte();
			short age = msg.body.readShort();
			UserInfo userInfo = new UserInfo(strName, userId, money, gold, sex, age); 
			String strJson = JSON.toJSONString(userInfo);
			logView.println("收到用户信息 : " + strJson);
			
			iStrNameLen = msg.body.readInt();	// 字符串名字长度
			byName = new byte[iStrNameLen];
			msg.body.readBytes(byName);
			strName = new String(byName);
			userId = msg.body.readInt();
			money = msg.body.readFloat();
			gold = msg.body.readLong();
			sex = msg.body.readByte();
			age = msg.body.readShort();
			userInfo = new UserInfo(strName, userId, money, gold, sex, age); 
			strJson = JSON.toJSONString(userInfo);
			logView.println("收到用户信息 : " + strJson);
			
			iStrNameLen = msg.body.readInt();	// 字符串名字长度
			byName = new byte[iStrNameLen];
			msg.body.readBytes(byName);
			strName = new String(byName);
			userId = msg.body.readInt();
			money = msg.body.readFloat();
			gold = msg.body.readLong();
			sex = msg.body.readByte();
			age = msg.body.readShort();
			userInfo = new UserInfo(strName, userId, money, gold, sex, age); 
			strJson = JSON.toJSONString(userInfo);
			logView.println("收到用户信息 : " + strJson);
		}
		else if(1002 == msg.id) {
			byte[] byMsg = new byte[msg.bodyLen];
			msg.body.readBytes(byMsg);
			logView.println("收到服务端响应的登陆消息：" + new String(byMsg));
		}
			
		
	}
}
